package com.tedu.entity;

import java.awt.*;

/**
 * 子弹实体类
 */
public class Bullet {
    private int x,y,w,h;
    private Dir dir;
    private Image bg;
//alt  insert

    @Override
    public String toString() {
        return "Bullet{" +
                "x=" + x +
                ", y=" + y +
                ", w=" + w +
                ", h=" + h +
                ", dir=" + dir +
                ", bg=" + bg +
                '}';
    }

    public Bullet() {
    }

    public Bullet(int x, int y, int w, int h, Dir dir, Image bg) {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        this.dir = dir;
        this.bg = bg;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getW() {
        return w;
    }

    public void setW(int w) {
        this.w = w;
    }

    public int getH() {
        return h;
    }

    public void setH(int h) {
        this.h = h;
    }

    public Dir getDir() {
        return dir;
    }

    public void setDir(Dir dir) {
        this.dir = dir;
    }

    public Image getBg() {
        return bg;
    }

    public void setBg(Image bg) {
        this.bg = bg;
    }

    //移动
    public void move() {
        switch (dir){
            case up:// 每次移动5个像素点
                y = y -4;
                break;  // 退出循环
            case down:
                y = y + 4;
                break;
            case left:
                x = x - 4;
                break;
            case right:
                x = x + 4;
                break;
        }
    }

    /**
     * 绘制子弹
     * @param g
     */
    public void draw(Graphics g) {
        g.drawImage(bg,x,y,w,h,null);
    }
}
